<template>
	 	<u-upload @on-success="success" :show-tips="false" ref="tag"  action="https://112.74.74.239/prod-api/wx/oss/upload"  :file-list="fileList"  maxCount="1" :header="header" :before-upload="beforeUpload" :auto-upload="true" :form-data="formdata"></u-upload>
</template>
<script > 
	export default { 
		props:{
			tag:String, 
			file:String, 
			pathFlag:Number,
		},
		data(){
		  return{
			   formdata:{},
			   header:{},
			   fileList: this.file ? [ { url: this.file,   type: 'image', status: 'success', }] :[],
		  }	 
		},
		created() {
			 
		},
		mounted() {
			 this.header = {
				 'content-type':'multipart/form-data',
				 Authorization: uni.getStorageSync('token')
			 },
			 this.formdata = {
				 pathFlag:this.pathFlag
			 }
		},
		methods:{
			beforeUpload(index, list) {
			  console.log(list[index]);			 
			},
			success(res){
				console.log(res);
				if(res.code == 200){
					var url = res.data.url;
					var obj = {};obj[this.tag] = res.data.url;
					if(this.pathFlag == 2){
						this.$store.dispatch("ztPicture", obj );
						console.log("存数据进入 ztPicture");
						console.log(this.$store.state.ztPicture);
					}else if(this.pathFlag == 3){
						this.$store.dispatch("asyncTmp", obj );
					} else if(this.pathFlag == 1){
						this.$store.dispatch("ztLocation", obj );
					}
				    
				}
			}
		}
	}
	
 
</script>